package com.yxy.flybird;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

public class ScoreManager {

	public static int GetBestScore(Context context, int type) {
		SharedPreferences prefs = context.getSharedPreferences(
				context.getPackageName() + ".score", Context.MODE_PRIVATE);
		int score = 0;
		switch (type) {
		case MainActivity.MODE_SIMP:
			score = prefs.getInt("bestscore_simp", 0);
			break;
		case MainActivity.MODE_GENE:
			score = prefs.getInt("bestscore_gene", 0);
			break;
		case MainActivity.MODE_DIFF:
			score = prefs.getInt("bestscore_diff", 0);
			break;
		case MainActivity.MODE_META:
			score = prefs.getInt("bestscore_meta", 0);
			break;

		default:
			break;
		}
		return score;
	}

	public static void SetBestScore(Context context, int newScore, int type) {

		if (newScore > GetBestScore(context, type)) {
			SharedPreferences prefs = context.getSharedPreferences(
					context.getPackageName() + ".score", Context.MODE_PRIVATE);

			Editor editor = prefs.edit();
			Log.i("jmc", "  mode = "+type+" scrore = "+newScore);
			switch (type) {
			case MainActivity.MODE_SIMP:
				editor.putInt("bestscore_simp", newScore);
				break;
			case MainActivity.MODE_GENE:
				editor.putInt("bestscore_gene", newScore);
				break;
			case MainActivity.MODE_DIFF:
				editor.putInt("bestscore_diff", newScore);
				break;
			case MainActivity.MODE_META:
				editor.putInt("bestscore_meta", newScore);
				break;

			default:
				break;
			}
			Log.i("jmc", "  do commit  ");
			editor.commit();
		}
	}
}
